import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../res/colors.dart';

class Toolbar extends StatefulWidget {
  final String title;
  final Color backgroundColor;
  final Color textColor;
  final String endTitle;
  final VoidCallback? back;
  final bool isShowEnd;

  const Toolbar({
    Key? key,
    this.title = "",
    this.endTitle = "",
    this.backgroundColor = Colors.white,
    this.textColor = Colors.black45,
    this.back,
    this.isShowEnd = false,
  }) : super(key: key);

  @override
  State<Toolbar> createState() => _ToolbarState();
}

class _ToolbarState extends State<Toolbar> {
  @override
  Widget build(BuildContext context) {
    return Material(
      color: widget.backgroundColor,
      child: SafeArea(
          child: Stack(
            alignment: AlignmentDirectional.center,
            children: [
              Positioned(
                left: 0,
                child: InkWell(
                  onTap: widget.back ?? () => Get.back(),
                  child: Container(
                      margin: const EdgeInsets.all(5),
                      child: Icon(
                        Icons.arrow_back,
                        color: Navigator.canPop(context)
                            ? Colors.black
                            : Colors.transparent,
                      )),
                ),
              ),
              Container(
                width: double.infinity,
                margin: const EdgeInsets.symmetric(vertical: 12),
                alignment: Alignment.center,
                child: Text(
                  widget.title,
                  overflow: TextOverflow.ellipsis,
                  maxLines: 1,
                  style: const TextStyle(color: Colors.black87, fontSize: 16),
                ),
              )
            ],
          )),
    );
  }
}


